package com.greenantmall.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.greenantmall.R;

public class SelectAreaLeftAdapter extends BaseAdapter {
	private Context mContext;
	private LayoutInflater mLayoutInflater;
	
	private List<AreaBean> mDataList;
	
	public static class AreaBean {
		public boolean isSelected = false;
		public String area;
		public int uptownCount;
	}
	
	public SelectAreaLeftAdapter(Context context, List<AreaBean> dataList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(mContext);
		mDataList = dataList;
	}

	@Override
	public int getCount() {
		if(mDataList != null) {
			return mDataList.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int arg0) {
		return arg0;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View child = convertView;
		ViewHolder holder = null;
		if(child == null) {
			child = mLayoutInflater.inflate(R.layout.select_area_list_left_item, null);
			holder = new ViewHolder(child);
			child.setTag(holder);
		}
		else {
			holder = (ViewHolder)child.getTag();
		}
		
		AreaBean bean = mDataList.get(position);
		holder.getTvArea().setText(bean.area);
		holder.getTvCount().setText("(" + bean.uptownCount + ")");
		if(bean.isSelected) {
			holder.getTvArea().setTextColor(mContext.getResources().getColor(R.color.green));
			holder.getTvCount().setTextColor(mContext.getResources().getColor(R.color.green));
		}
		else {
			holder.getTvArea().setTextColor(Color.parseColor("#454e56"));
			holder.getTvCount().setTextColor(Color.parseColor("#454e56"));
		}
		
		return child;
	}
	
	private class ViewHolder {
		private View mContentView;
		private TextView mTvArea;
		private TextView mTvCount;
		
		public ViewHolder(View contentView) {
			mContentView = contentView;
		}

		public TextView getTvArea() {
			if(mTvArea == null) {
				mTvArea = (TextView)mContentView.findViewById(R.id.select_area_list_left_item_tv_0);
			}
			return mTvArea;
		}

		public TextView getTvCount() {
			if(mTvCount == null) {
				mTvCount = (TextView)mContentView.findViewById(R.id.select_area_list_left_item_tv_1);
			}
			return mTvCount;
		}
	}
}








